package day240515.e1_my;

public class Dog implements MyComparable {
    String name;
    double weight;

    public Dog(String name, double weight) {
        this.name = name;
        this.weight = weight;
    }

    @Override
    public String toString() {
        return this.name + "(" + this.weight + ")";
    }

    @Override
    public int compareTo(MyComparable object) {
        if (object instanceof Dog dog) {
            if (this.weight == dog.weight) return 0;
            return (this.weight - dog.weight > 0) ? 1 : -1;
        } else {
            throw new ClassCastException("比较类型不匹配");
        }
    }
}
